package com.qpf.spring.cloud.service.admin.controller;

import com.qpf.spring.cloud.commons.utils.JsonUtils;
import com.qpf.spring.cloud.service.admin.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    private DemoService demoService;
    @Autowired
    public DemoController(DemoService demoService) {
        this.demoService = demoService;
    }


    @GetMapping("demo")
    public String demo(@RequestParam(value = "message", required = false) String message) {
        return String.format("demo: %s", message);
    }
    @GetMapping("users")
    public String users() {
        String result;
        try {
            result = JsonUtils.obj2json(demoService.selectAll());
        } catch (Exception e) {
            result = "";
        }
        return result;
    }
}
